Skip to content

Fix DType::from rejecting S16, U16 and F16 - #391

Open
chiliec wants to merge 1 commit into
arrayfire:masterfrom
chiliec:fix-dtype-from-u32-f16
Open

chiliec wants to merge 1 commit into
arrayfire:masterfrom
chiliec:fix-dtype-from-u32-f16

Conversation

@chiliec

@chiliec chiliec commented Oct 16, 2026

Copy link
Copy Markdown

Fixes #386.

DType::from(u32) asserted t <= DType::U64 as u32 (9), but the enum extends to F16 = 12:

U64 = 9, S16 = 10, U16 = 11, F16 = 12,

So the conversion panicked for three of the crate's own supported types. Since Array::get_type() calls DType::from, any f16/s16/u16 array panicked on get_type() (and on Debug, which calls it):

let a = randu::<half::f16>(dim4!(3, 3));
let t = a.get_type();   // panicked before this fix

The fix bounds the assert at F16 instead of U64.

Tests

Added dtype_from_u32_roundtrip in core::defines::tests, asserting every discriminant from F32 through F16 round-trips through DType::from.

Verification

The crate links the native ArrayFire library, which isn't installable on this CI-less machine, so I linked the test binary against a stub libaf.so exporting the referenced af_* symbols (this bug is pure Rust logic and never calls into the native library at runtime).

  • Before the fix: cargo test --lib dtype_from_u32_roundtrip fails — assertion failed: DType::F32 as u32 <= t && t <= DType::U64 as u32 at util.rs:78 (panics at t = 10).
  • After the fix: test core::defines::tests::dtype_from_u32_roundtrip ... ok.

The upper bound was DType::U64 (9), but the enum extends to F16 (12),
so DType::from panicked for the crate's own S16/U16/F16 types -- which
Array::get_type() returns for f16 arrays.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DType::from rejects S16, U16 and F16

1 participant